package com.mxpio.erp.purchase.service.impl;

import com.mxpio.erp.common.enums.OrderStatusEnums;
import com.mxpio.erp.common.purchase.entity.PurchaseOrder;
import com.mxpio.erp.common.purchase.entity.PurchaseOrderLine;
import com.mxpio.erp.common.purchase.service.PurchaseOrderLineService;
import com.mxpioframework.jpa.JpaUtil;
import com.mxpioframework.jpa.query.Criteria;
import com.mxpioframework.system.service.impl.BaseServiceImpl;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class PurchaseOrderLineServiceImpl extends BaseServiceImpl<PurchaseOrderLine> implements PurchaseOrderLineService {

    @Transactional(readOnly = false)
    @Override
    public Page<PurchaseOrderLine> listPage(Pageable page, Criteria c){
        return JpaUtil.linq(PurchaseOrderLine.class)
                .collect("bizNo", PurchaseOrder.class, "bizNo")
                .exists(PurchaseOrder.class)
                    .equalProperty("bizNo", "bizNo")
                    .notEqual("closeStatus", OrderStatusEnums.CloseStatus.CLOSED.getStatusCode())
                    .equal("bpmnStatus", OrderStatusEnums.BpmnStatus.AUDITED.getStatusCode())
                    .notEqual("orderStatus", OrderStatusEnums.OrderStatus.CLEARED.getStatusCode())
                .end()
                .where(c)
                .paging(page);
    }
}
